package com.hand.demo.api.controller.v1;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.annotation.SortDefault;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.mybatis.pagehelper.domain.Sort;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.mybatis.helper.SecurityTokenHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.hand.demo.app.service.HhrTaTagsService;
import com.hand.demo.domain.entity.HhrTaTags;
import com.hand.demo.domain.repository.HhrTaTagsRepository;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 人才标签表(HhrTaTags)表控制层
 *
 * @author
 * @since 2025-07-02 11:09:51
 */

@RestController("hhrTaTagsController.v1")
@RequestMapping("/v1/{organizationId}/hhr-ta-tagss")
public class HhrTaTagsController extends BaseController {

    @Autowired
    private HhrTaTagsRepository hhrTaTagsRepository;

    @Autowired
    private HhrTaTagsService hhrTaTagsService;

    @ApiOperation(value = "人才标签表列表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping
    public ResponseEntity<Page<HhrTaTags>> list(HhrTaTags hhrTaTags, @PathVariable Long organizationId,
                                                @ApiIgnore @SortDefault(value = HhrTaTags.FIELD_ID,
                                                        direction = Sort.Direction.DESC) PageRequest pageRequest) {
        Page<HhrTaTags> list = hhrTaTagsService.selectList(pageRequest, hhrTaTags);
        return Results.success(list);
    }

    @ApiOperation(value = "人才标签表明细")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping("/{id}/detail")
    public ResponseEntity<HhrTaTags> detail(@PathVariable Long id) {
        HhrTaTags hhrTaTags = hhrTaTagsRepository.selectByPrimary(id);
        return Results.success(hhrTaTags);
    }

    @ApiOperation(value = "创建或更新人才标签表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @PostMapping
    public ResponseEntity<List<HhrTaTags>> save(@PathVariable Long organizationId, @RequestBody List<HhrTaTags> hhrTaTagss) {
        validObject(hhrTaTagss);
        SecurityTokenHelper.validTokenIgnoreInsert(hhrTaTagss);
        hhrTaTagss.forEach(item -> item.setTenantId(organizationId));
        hhrTaTagsService.saveData(hhrTaTagss);
        return Results.success(hhrTaTagss);
    }

    @ApiOperation(value = "删除人才标签表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @DeleteMapping
    public ResponseEntity<?> remove(@RequestBody List<HhrTaTags> hhrTaTagss) {
        SecurityTokenHelper.validToken(hhrTaTagss);
        hhrTaTagsRepository.batchDeleteByPrimaryKey(hhrTaTagss);
        return Results.success();
    }

}

